<template>
  <BasicTable @register="registerTable" />
</template>
<script lang="ts">
  import { defineComponent } from 'vue';
  import { listApi } from '/@/api/set/log';
  import { BasicTable, useTable, BasicColumn, FormSchema } from '/@/components/Table/index';
  import { businessTypes } from '/@/assets/dic';
  import formatDic from '/@/utils/formatDic';

  const searchFormSchema: FormSchema[] = [
    {
      field: 'title',
      label: '目标名称：',
      component: 'Input',
      colProps: {
        span: 8,
      },
    },
    {
      field: 'operName',
      label: '操作人：',
      component: 'Input',
      colProps: {
        span: 8,
      },
    },
    {
      field: 'operTime',
      label: '操作时间：',
      component: 'DatePicker',
      colProps: {
        span: 8,
      },
    },
  ];

  const columns: BasicColumn[] = [
    {
      title: '目标名称',
      dataIndex: 'title',
    },
    {
      title: '目标类型',
      dataIndex: 'businessType',
      format: formatDic(businessTypes),
    },
    {
      title: '操作类型',
      dataIndex: 'requestMethod',
    },
    {
      title: '状态',
      dataIndex: 'status',
      format(value) {
        return ['成功', '失败'][value];
      },
    },
    {
      title: '操作时间',
      dataIndex: 'operTime',
    },
    {
      title: '操作人',
      dataIndex: 'operName',
    },
    {
      title: '失败原因',
      dataIndex: 'errorMsg',
    },
  ];

  export default defineComponent({
    name: 'OperationLog',
    components: {
      BasicTable,
    },
    setup() {
      const [registerTable] = useTable({
        api: listApi,
        useSearchForm: true,
        columns: columns,
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
        },
        searchInfo: {
          depId: 100,
        },
      });
      return {
        registerTable,
      };
    },
  });
</script>
<style lang="less" scoped></style>
